<template>
  <el-dialog
      class="dialog"
      title="修改计划"
      width="30%"
      :close-on-click-modal="false"
      :before-close="handleClose"
      :visible.sync="dialogFormVisible"
      @open="$store.commit('CHANGEBTNSTATUS', false)">
    <el-form
        style="padding: 20px"
        :model="planForm"
        ref="planForm"
        label-width="80px"
        label-position="right"
    >
      <el-form-item label="计划名称" prop="planName">
        <el-input
            size="mini"
            v-model="planForm.planName"
           
        ></el-input>
      </el-form-item>
      <el-form-item label="计划类型" prop="planType">
        <el-select
            size="mini"
            v-model="planForm.planType"
           
        >
          <el-option label="电话计划" value="A"></el-option>
          <el-option label="上门计划" value="B"></el-option>
          <el-option label="其他计划" value="C"></el-option>
          <!-- <el-option label="上级下发" value="E"></el-option> -->
        </el-select>
      </el-form-item>
      <el-form-item label="计划时间" prop="compleTime">
        <el-date-picker
            v-model="planForm.compleTime"
            type="date"
            placeholder="选择日期"
            size="mini"
        >
        </el-date-picker>
      </el-form-item>
      <el-form-item label="计划备注">
        <el-input
            type="textarea"
            v-model="planForm.planRemarks"
            autocomplete="off"
        ></el-input>
      </el-form-item>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button size="mini" @click="cancel">取 消</el-button>
      <el-button size="mini" type="primary" :disabled="$store.state.btnDisabled"  @click="updateSave('planForm')">保 存</el-button>
    </div>
  </el-dialog>
</template>

<script>
import planManagement from "@/http/apis/modules/planManagement";
import { Message } from "element-ui";
import CustomBpmnViewer from "./customer-viewer";
import axios from "axios";

export default {
  props: {
    dialogFormVisible: {
      type: Boolean,
      default: false,
    },
    planForm: {
      type: Object,
      default: () => {},
    }
  },
  name: "UpdatePlan",

  components: {},
  data() {
    return {
      bpmnViewer: null,
    };
  },

  created() {
  },
  methods: {
    updateSave(formName) {
      this.$refs[formName].validate(async (valid) => {
        if (valid) {
          this.$store.commit("CHANGEBTNSTATUS", true);
          console.log(typeof this.planForm.compleTime)
          if(!typeof this.planForm.compleTime == "string") {
            this.planForm.compleTime = this.planForm.compleTime.getTime();
          } else {
            this.planForm.compleTime = new Date(this.planForm.compleTime).getTime()
          }
          let data = {
            ...this.planForm
          }
          console.log(data)
          let re = await planManagement.updatePlanApi(data);
          let { code, msg } = re.data;
          if (code == "SUCCESS") {
            Message({
              type: "success",
              message: msg,
            });
            
            this.$emit("updatePlan");
          } else {
            Message({
              type: "danger",
              message: msg,
            });
            this.$emit("updatePlan");
          }
        }
        this.$store.commit("CHANGEBTNSTATUS", false);
      });
    },
    handleClose() {
      this.$emit("cancel");
    },
    cancel() {
      this.$emit("cancel");
    }
  }
};
</script>

<style lang="less">

</style>
